{extend name="public/base"}

{block name="title"}
订单评价
{/block}

{block name="style"}
{css href="/static/wechat/css/homepage.css" /}

{/block}

{block name="body"}
<div class="pageControl orderDetails">
    <div class="msui_nav msui_navTop" style="border-bottom: 1px solid #cccccc;">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">订单评价</h1>
    </div>
    <div class="weui-top">
        <!--感觉怎么样打个分吧-->
        <div class="fu_div">
            <span class="solid_"></span>
            <h1 class="solid_mid">感觉怎么样，打个分吧</h1>
            <span class="solid_"></span>
        </div>
        <form action="{:url('save_comment')}" id="comment_form">
            <!--点星星打分-->
            <div class="dian_star">
                <i class="i_star"></i>
                <i class="i_star"></i>
                <i class="i_star"></i>
                <i class="i_star"></i>
                <i class="i_star"></i>
                <input name="level" type="hidden">
            </div>

            <!--点击默认评价标签-->
            <div class="dian_label">
                <!--<span class="mo_p"></span>-->
            </div>
            <input name="label" type="hidden">

            <!--input提交评论-->
            <div class="ipt_sub">
                <textarea name="content" class="ping_ipt" type="text" placeholder="说点什么吧~"/></textarea>
                <!--<textarea class="ping_tarea" name="" rows="" cols="" placeholder="说点什么吧">
                </textarea>-->
                <input class="ti_jiao" type="submit"/>
            </div>
            <input type="hidden" name="obj_id" value="{$order_id}">
            <input type="hidden" name="type" value="{$type}">
        </form>
    </div>

</div>

<!-- loading toast -->
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>

{/block}


{block name="javascript"}
{js href="/static/wechat/js/homepage.js" /}
<script>
    $(function () {
        var obj = {
            labels : ''
        }
        $.get("{:url('get_labels')}", function (msg) {
            obj.labels = msg.data;
        }, 'json');

        $(".i_star").click(function () {
            var level = $("input[name='level']").val();
            if (obj.labels[level]) {
                var new_val = getRandom({'arry':obj.labels[level],'range':5});
                var lalebs = [];
                var len = new_val.length;
                for(var i = 0; i < len; i++) {
                    lalebs.push('<span class="mo_p">'+ new_val[i].name +'</span>');
                }
                $(".dian_label").html(lalebs.join(''));
            } else{
                $(".dian_label").html('');
            }
        });

        function getRandom(opt) {
            var old_arry = opt.arry,
                    range = opt.range;
            //防止超过数组的长度
            range = range > old_arry.length?old_arry.length:range;
            var newArray = [].concat(old_arry), //拷贝原数组进行操作就不会破坏原数组
                    valArray = [];
            for (var n = 0; n < range; n++) {
                var r = Math.floor(Math.random() * (newArray.length));
                valArray.push(newArray[r]);
                //在原数组删掉，然后在下轮循环中就可以避免重复获取
                newArray.splice(r, 1);
            }
            return valArray;
        }




        $("#comment_form").submit(function (e) {
            e.preventDefault();
            var level = $("input[name='level']").val();
            if (!level) {
                alert('请选择分数');
                return false;
            }

            var _this = $(this);
            $.ajax({
                type : 'POST',
                url : _this.attr('action'),
                data : _this.serialize(),
                dataType : 'json',
                success : function (msg) {
                    console.log(msg)
                    if (msg.code == 200) {
                        $.alert("发表成功！");
                        if($('#comment_form input[name="type"]').val()!=5){
                            window.location.href="{:url('orders/index')}";
                        }else{
                            window.location.href="{:url('r_orders/deal_order')}?status=1";
                        }
                    } else {
                        var code = msg.code;
                        $.alert(error_code[code]);
                    }
                }
            });
        })
    })
</script>
{/block}